//package com.gxd.rocketmq.config;
//
//import com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;
//import com.alibaba.rocketmq.client.exception.MQClientException;
//import com.gxd.rocketmq.exception.RocketMQException;
//import com.gxd.rocketmq.message.MessageListener;
//import com.gxd.rocketmq.message.MessageProcessor;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.SpringBootConfiguration;
//import org.springframework.context.annotation.Bean;
//
///**
// * @Author:gxd
// * @Description:
// * @Date: 15:32 2018/1/10
// * @Modified By:
// */
//@SpringBootConfiguration
//public class RocketMQConsumerConfiguration {
//    public static final Logger LOGGER = LoggerFactory.getLogger(RocketMQConsumerConfiguration.class);
//    @Value("${rocketmq.consumer.namesrvAddr}")
//    private String namesrvAddr;
//    @Value("${rocketmq.consumer.groupName}")
//    private String groupName;
//    @Value("${rocketmq.consumer.topic}")
//    private String topic;
//    @Value("${rocketmq.consumer.tag}")
//    private String tag;
//    @Value("${rocketmq.consumer.consumeThreadMin}")
//    private int consumeThreadMin;
//    @Value("${rocketmq.consumer.consumeThreadMax}")
//    private int consumeThreadMax;
//    @Value("${rocketmq.consumer.consumerMessageBatchMaxSize}")
//    private int consumerMessageBatchMaxSize;
//
//    @Autowired
//    @Qualifier("messageProcessorImplTest")
//    private MessageProcessor messageProcessor;
//
//    @Bean
//    public DefaultMQPushConsumer getRocketMQConsumer() throws RocketMQException {
//        if (StringUtils.isBlank(groupName)){
//            throw new RocketMQException("groupName is null !!!");
//        }
//        if (StringUtils.isBlank(namesrvAddr)){
//            throw new RocketMQException("namesrvAddr is null !!!");
//        }
//        if (StringUtils.isBlank(topic)){
//            throw new RocketMQException("topic is null !!!");
//        }
//        if (StringUtils.isBlank(tag)){
//            throw new RocketMQException("tag is null !!!");
//        }
//        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(groupName);
//        consumer.setNamesrvAddr(namesrvAddr);
//        consumer.setConsumeThreadMin(consumeThreadMin);
//        consumer.setConsumeThreadMax(consumeThreadMax);
//        //一次消费一条
//        consumer.setConsumeMessageBatchMaxSize(consumerMessageBatchMaxSize);
//        MessageListener messageListener = new MessageListener();
//        messageListener.setMessageProcessor(messageProcessor);
//        consumer.registerMessageListener(messageListener);
//        try {
//            consumer.subscribe(topic,this.tag);
//            consumer.start();
//            LOGGER.info("consumer is start !!! groupName:{},topic:{},namesrvAddr:{}",groupName,topic,namesrvAddr);
//        }catch (MQClientException e){
//            LOGGER.error("consumer is start !!! groupName:{},topic:{},namesrvAddr:{}",groupName,topic,namesrvAddr,e);
//            throw new RocketMQException(e);
//        }
//        return consumer;
//    }
//}
